import format from '@dfeidao/atom-web/dt/format';
import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import set from '@dfeidao/atom-web/local/set';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import render from '@dfeidao/atom-web/render/render';
import set_node_cls from '@dfeidao/atom-web/ui/set-node-cls';
import show from '@dfeidao/atom-web/ui/show';
import p001 from './p001';
import p002 from './p002';
import p003 from './p003';

export default async function a001(fd: IFeidaoAiBrowserComponent, d: string) {
	// todo
	const up_particulars = fd.data.node.querySelector<HTMLDivElement>('[data-id="up-particulars"]');
	set_node_cls(up_particulars, 'display-n', false);
	show(fd.data.node);
	set(fd,"staff_no", d);
	const d1 =d;
	// 根据编号去查询数据
	const res1 = await nodejs<Array<{ sponsor: string, inform_title: string, inform_content: string, notification_time: number }>>
		('notification-notice/zj-000003/s001',
			{
				filter: {
					d: d1
				}
			});

	const newres1 = res1.map((n) => {
		return { ...n, notification_time: format(n.notification_time, 2) };
	});
	render(fd, newres1, p001, 'p001', "inner");
	const res2 = await nodejs<Array<{ annex_file: string, annex_no: string, annex_name: string }>>
		('notification-notice/zj-000003/s002',
			{
				filter: {
					d: d1
				}
			});
	if (res2.length < 1) {
		render(fd, "", p002, 'p002', "inner");
	} else {
		render(fd, res2, p002, 'p002', "inner");
	}
	const res3 = await nodejs<Array<{ pub_user_no: string, pub_user_name: string, length: number }>>
		('notification-notice/zj-000003/s003',
			{
				filter: {
					d: d1
				}
			});
	const num = 9;
	const data = res3.map((v) => {
		return { ...v, length: num };
	});
	const arr = Array();
	for (let i = 0; i < data.length; i++) {
		if (i < 8) {
			arr.push(data[i]);
		}
	}
	if (res3.length > 8) {
		const zhankai = fd.data.node.querySelector<HTMLDivElement>('[data-id="zhankai"]');
		set_node_cls(zhankai, 'display-n', false);
	}
	if (res3.length < 1) {
		render(fd, "", p003, 'p003', "inner");
	} else {
		render(fd, arr, p003, 'p003', "inner");
	}

}
